package com.ctbri.arrays;

import java.lang.reflect.Array;
import java.util.Arrays;

import com.ctbri.util.Generator;

public class Ex14 {
	
	public static void primitive(Object array, Generator<?> gen) {
		int size = Array.getLength(array);
		Class<?> type = array.getClass().getComponentType();
		for(int i = 0; i < size; i++) {
			if(type == Boolean.TYPE) {
				Array.setBoolean(array, i, (Boolean)gen.next());
			} else if(type == Character.TYPE) {
				Array.setChar(array, i, (Character)gen.next());
			} else if(type == Byte.TYPE) {
				Array.setByte(array, i, (Byte)gen.next());
			} else if(type == Short.TYPE) {
				Array.setShort(array, i, (Short)gen.next());
			} else if(type == Integer.TYPE) {
				Array.setInt(array, i, (Integer)gen.next());
			} else if(type == Long.TYPE) {
				Array.setLong(array, i, (Long)gen.next());
			} else if(type == Float.TYPE) {
				Array.setFloat(array, i, (Float)gen.next());
			} else if(type == Double.TYPE) {
				Array.setDouble(array, i, (Double)gen.next());
			}
		}
	}
	public static void main(String[] args) {
		int size = 6;
		boolean[] a1 = new boolean[size];
		float[] a2 = new float[size];
		primitive(a1, new CountingGenerator.Boolean());
		primitive(a2, new CountingGenerator.Float());
		System.out.println("a1 = " + Arrays.toString(a1));
		System.out.println("a2 = " + Arrays.toString(a2));
	}

}
